package com.zikao.question.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.zikao.question.entity.Text2Entity;
import com.zikao.question.service.Text2Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zikao.common.utils.PageUtils;
import com.zikao.common.utils.Query;

import com.zikao.question.dao.QuestionDao;
import com.zikao.question.entity.QuestionEntity;
import com.zikao.question.service.QuestionService;


@Service("questionService")
public class QuestionServiceImpl extends ServiceImpl<QuestionDao, QuestionEntity> implements QuestionService {
    @Autowired
    private Text2Service text2Service;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<QuestionEntity> page = this.page(
                new Query<QuestionEntity>().getPage(params),
                new QueryWrapper<QuestionEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<QuestionEntity> selectByMap(Map<String, Object> params) {

        return baseMapper.selectByMap(params);
    }

    @Override
    public void saveQuestion(QuestionEntity question) {
        Text2Entity text2Entity = new Text2Entity();
        text2Entity.setContent(question.getContent());
        text2Service.save(text2Entity);

        question.setTextId(text2Entity.getId());
        baseMapper.insert(question);
    }

    @Override
    public List<QuestionEntity> selectList(QueryWrapper wrapper) {
        return baseMapper.selectList(wrapper);
    }

    @Override
    public PageUtils queryPage(Map<String, Object> params, Wrapper queryWrapper) {
        IPage<QuestionEntity> page = this.page(
                new Query<QuestionEntity>().getPage(params),
                queryWrapper
        );
        return new PageUtils(page);
    }

    @Override
    public List<QuestionEntity> selectBatchIds(List<Long> questionIds) {
        return baseMapper.selectBatchIds(questionIds);
    }
}